package com.wyzz.hr.action;

import java.util.*;
import org.apache.commons.lang.StringUtils;

import com.wyzz.hr.base.BaseAction;
import com.wyzz.hr.bo.IEmployeeBo;
import com.wyzz.hr.bo.IOrgheadsBo;
import com.wyzz.hr.pojo.Location;
import com.wyzz.hr.pojo.Orgheads;
import com.wyzz.hr.spring.SpringBeanFactory;

public class LocationManagementAction extends BaseAction {

	public LocationManagementAction() {
	}

	public String execute() throws Exception {
		allLocation = getDrillDown("Location", new String[] { "1" });
		Map locationHeadMap = new HashMap();
		IOrgheadsBo headsBo = (IOrgheadsBo) SpringBeanFactory
				.getBean("headsBo");
		List orgheadlist = headsBo.listOrgheadNo("locationheader");
		Orgheads head;
		for (Iterator it = orgheadlist.iterator(); it.hasNext(); locationHeadMap
				.put(head.getOrgheadsOrgNo(), head.getOrgheadsEmpNo()))
			head = (Orgheads) it.next();

		IEmployeeBo empBo = (IEmployeeBo) getBean("empBo");
		Map empMap = empBo.getEmployeeMap(locationHeadMap.values());
		Iterator it = allLocation.iterator();
		do {
			if (!it.hasNext())
				break;
			Location location = (Location) it.next();
			String headerId = (String) locationHeadMap.get(location.getId());
			if (!StringUtils.isEmpty(headerId)) {
				location.setHeadNo(headerId);
				location.setHeadName((String) empMap.get(headerId));
			}
		} while (true);
		return "success";
	}

	public List getAllLocation() {
		return allLocation;
	}

	public void setAllLocation(List allLocation) {
		this.allLocation = allLocation;
	}

	private static final long serialVersionUID = 0xf65d9dd88c88254fL;
	private List allLocation;
}
